# -*- coding: utf-8 -*-
# @Time    : 2021/3/31 20:27
# @Author  : N
# @Email   : 
# @File    : 三乐购物系统.py
# @Software: PyCharm
food={"1":{"name":"苹果","price":11,},
     "2":{"name":"香蕉","price":55}}
shoppingCar={}
usdname = {"root": 123456}
print(usdname.keys())
while True:
    print("欢迎光临".center(100, "*"))
    a = input("******注册请按1 \n**进入登录请按2: ")
    if int(a) == 1:
        b1 = input("请输入你要注册的用户名：")
        c2 = int(input("请输入密码："))
        print("注册成功")
        ff1 = {b1: c2}
        usdname.update(ff1)
        continue
    if int(a) ==2:
        while True:
            b = input("请输入用户名:")
            if b in usdname:
                c = int(input("请输入密码:"))

                if usdname[b] ==c:
                        print("登录成功")
                        ys = int(input("请输入购物预算："))
                        ck = input("查看商品信息请按1：")
                        if int(ck) == 1:
                            for i, j in food.items():
                                print(f"编号：{i}", f"名字：{j['name']}", f"价格：{j['price']}")

                        while True:
                            d = input("请输入你要购买的商品编号,如果想退出请按exit：")
                            if str(d) =="exit":
                                print("欢迎下次光临".center(100,"*"))
                                break
                            if d in food.keys():
                                e = int(input("请输入你需要购买的数量："))
                                if e * int(food[d]['price']) > ys:
                                    print("你的余额不足")
                                if e * int(food[d]['price']) <=ys:
                                    ys = ys - e * int(food[d]['price'])

                                    f = {d:e}
                                    for key, value in shoppingCar.items():
                                        if key in f:
                                            f[key] += value
                                        else:
                                            f[key] = value
                                    shoppingCar.update(f)
                                    print("你的购物车：", shoppingCar, "你的余额还有", ys, "元")
                            else:
                                print("没有这个商品")
                                continue
                else:
                    print("密码错误")
            else:
                print("用户名错误")
